<?php
/***************************
 * mail actions
 * @author loi-vp
 ***************************/
class mailActions extends sfActions
{
 

	/***************************
	* send mail for lost password
	* @param sfRequest $request A request object
	***************************/
	public function executeMailLostPassword(sfWebRequest $objRequest)
	{
		try {
			
			$strMailAddress = $objRequest->getParameter('txtMailAddress');
			$this->forward404Unless($strMailAddress);
			$aryUser = UserTablePeer::getUserByLoginId($strMailAddress);
			$form = $this->setValueForUserForm($aryUser);
			/* send mail to user */
			myMailUtil::sendMail($form, myMailUtil::getMailTypeLostPassword());
			$this->redirect("@home");
		}
		catch (Exception $ex) {
			/* display error message when send mail fail */
			$this->getUser()->setFlash('mail_error', myMailUtil::getMailErrorMessage());
			$this->redirect("@lost_password");
		}

	}
	/* Set value to form for displaying
	 *
	 * @param array $aryUser
	 * @return UserForm
	 */
	private function setValueForUserForm($aryUser)
	{
		$form = new UserForm();

		$form->setDefaults(array(
			'txtMailAddress' => $aryUser['MAIL_ADDRESS'],
			'txtPassword' => $aryUser['PASSWORD'],
		));

		return $form;
	}

}


